package GUI;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

import javax.swing.JPanel;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

/**
 * Interfaz para las opciones de la GUI principal.
 * @author Caneva Francisco
 * @author Holtz Jordan
 *
 */
public class Settings extends javax.swing.JFrame {
	private JTabbedPane tabs;
	private JLabel textcolor;
	private JButton aplicarcamb;
	private JLabel Other;
	private JButton elejforeg;
	private JLabel foreground;
	private JButton exit;
	private JComboBox tipos;
	private JLabel tipoletra;
	private JComboBox tamanos;
	private JLabel tamaletra;
	private JComboBox letras;
	private JLabel textfont;
	private JButton elegircolor;

	/**
	* Auto-generated main method to display this JFrame
	*/

	public Settings(mainFrame ma) {
		super();
		initGUI(ma);
	}
	
	private void initGUI(final mainFrame ma) {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{	
				setLocationRelativeTo(null);
				setVisible(true);
				this.setTitle("Opciones");
				tabs = new JTabbedPane();
				getContentPane().add(tabs, BorderLayout.CENTER);
				tabs.setPreferredSize(new java.awt.Dimension(419, 267));
//				tabs.setLayout(tabsLayout);
				JPanel cp=new JPanel();
				JPanel lp=new JPanel();
				tabs.addTab("Consola", cp);
				cp.setLayout(null);
				cp.setPreferredSize(new java.awt.Dimension(449, 271));
				{
					textcolor = new JLabel();
					cp.add(textcolor);
					textcolor.setText("<html>Elija el color con que se muestra la consola:</html>");
					textcolor.setLayout(null);
					textcolor.setBounds(27, 22, 302, 16);
				}
				{
					elegircolor = new JButton();
					cp.add(elegircolor);
					elegircolor.setText("Elegir");
					elegircolor.setLayout(null);
					elegircolor.setBounds(395, 19, 73, 23);
					elegircolor.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							JColorChooser cc=new JColorChooser();
							Color bgColor = cc.showDialog(cc,
						                                 "Elija Background Color",
						                                 getBackground());
						    if (bgColor != null)
						    	ma.changeColors(bgColor, ma.getConsole().getForeground());
						 }
					});
				}
				{
					textfont = new JLabel();
					cp.add(textfont);
					textfont.setText("Elija la tipo y tamano de letra:");
					textfont.setLayout(null);
					textfont.setBounds(27, 104, 302, 16);
				}
//				{
					String[] fontsnames=new String[] {"", "Comic Sans MS", "Courier New", "Arial", "System" };
					final ComboBoxModel letrasModel = new DefaultComboBoxModel(fontsnames);
					letras = new JComboBox();
					cp.add(letras);
					letras.setModel(letrasModel);
					letras.setBounds(394, 101, 73, 23);
//				}
//				{
					tamaletra = new JLabel();
					cp.add(tamaletra);
					tamaletra.setText("Elija el tamano de letra para la consola:");
					tamaletra.setLayout(null);
					tamaletra.setBounds(27, 146, 302, 16);
//				}
//				{
					Integer[] tam=new Integer[]{null,8, 10, 12, 14, 16, 20};
					final ComboBoxModel tamanosModel = new DefaultComboBoxModel(tam);
					tamanos = new JComboBox();
					cp.add(tamanos);
					tamanos.setModel(tamanosModel);
					tamanos.setBounds(394, 143, 73, 23);
//				}
//				{
					tipoletra = new JLabel();
					cp.add(tipoletra);
					tipoletra.setText("Elija el tipo de letra para la consola:");
					tipoletra.setLayout(null);
					tipoletra.setBounds(27, 188, 302, 16);
//				}
//				{
					Integer[] tip=new Integer[]{null,0,1,2};
					final ComboBoxModel tiposModel = new DefaultComboBoxModel(tip);
					tipos = new JComboBox();
					cp.add(tipos);
					tipos.setModel(tiposModel);
					tipos.setBounds(394, 185, 73, 23);
//				}
				{
					exit = new JButton();
					cp.add(exit);
					exit.setText("Salir");
					exit.setLayout(null);
					exit.setBounds(392, 291, 76, 32);
					exit.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							setVisible(false);
						}
					});
				}
				{
					foreground = new JLabel();
					cp.add(foreground);
					foreground.setText("<html>Elija el color con el cual se mostrara las letras de la consola:<html>");
					foreground.setLayout(null);
					foreground.setBounds(27, 54, 330, 34);
				}
				{
					elejforeg = new JButton();
					cp.add(elejforeg);
					elejforeg.setText("Elegir");
					elejforeg.setLayout(null);
					elejforeg.setBounds(395, 60, 73, 23);
					elejforeg.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							JColorChooser cc=new JColorChooser();
							Color bgColor = cc.showDialog(cc,
						                                 "Elija Foreground Color",
						                                 getBackground());
						    if (bgColor != null)
						    	ma.changeColors(ma.getConsole().getBackground(), bgColor);
						}
					});
				}
				{
					aplicarcamb = new JButton();
					cp.add(aplicarcamb);
					aplicarcamb.setText("<html>Aplicar cambios</html>");
					aplicarcamb.setBounds(245, 291, 136, 32);
					aplicarcamb.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							if(!letrasModel.getSelectedItem().equals("")&&
									tiposModel.getSelectedItem()!=null&&
									tamanosModel.getSelectedItem()!=null)
								ma.changeFonts((String)letrasModel.getSelectedItem(),
										(Integer)tiposModel.getSelectedItem(),
										(Integer)tamanosModel.getSelectedItem());
						}
					});
				}
				tabs.addTab("Otros", lp);
				{
					Other = new JLabel();
					lp.add(Other);
					Other.setText("Todavia no implementado");
				}
			}
			pack();
			this.setSize(500, 400);
		} catch (Exception e) {
			ExceptionGUI eg = new ExceptionGUI();
		}
	}

}
